package com.shuzixiangcun.controller.front;

import com.shuzixiangcun.entity.HealthRecords;

import com.shuzixiangcun.service.front.HealthRecordsFServiceImpl;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (HealthRecords)表控制层
 *
 * @author makejava
 * @since 2024-07-03 14:39:35
 */
@RestController
@RequestMapping("healthRecords")
public class HealthRecordsFController {
    /**
     * 服务对象
     */
    @Resource
    private HealthRecordsFServiceImpl healthRecordsService;



    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<HealthRecords> queryById(@PathVariable("id")Integer id) {
        return ResponseEntity.ok(this.healthRecordsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param healthRecords 实体
     * @return 新增结果
     */
    @PostMapping("addHealthRecords")
    public ResponseEntity<HealthRecords> add(HealthRecords healthRecords) {
        return ResponseEntity.ok(this.healthRecordsService.insert(healthRecords));
    }

    /**
     * 编辑数据
     *
     * @param healthRecords 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<HealthRecords> edit(HealthRecords healthRecords) {
        return ResponseEntity.ok(this.healthRecordsService.update(healthRecords));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById( Integer id) {
        return ResponseEntity.ok(this.healthRecordsService.deleteById(id));
    }

    @GetMapping("queryListHealths")
    public ResponseEntity<List<HealthRecords>> queryListHealths(Integer user_id) {
        return ResponseEntity.ok(this.healthRecordsService.getList(user_id));
    }

}

